//
//  WFFarmListCellTableViewCell.m
//  WisdomFarm
//
//  Created by sky on 2017/11/10.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFFarmListCellTableViewCell.h"

@interface WFFarmListCellTableViewCell()

@property (nonatomic, strong) UIImageView *selectIconView;
@property (nonatomic, strong) UIButton *editButton;
@property (nonatomic, strong) UIButton *deleteButton;

@end

@implementation WFFarmListCellTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.offset(0);
            make.left.offset(13);
        }];
        
        _selectIconView = [[UIImageView alloc] init];
        [self.contentView addSubview:_selectIconView];
        [_selectIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.right.offset(-13);
            make.width.height.mas_equalTo(25);
        }];
        
        _deleteButton = [[UIButton alloc] init];
        [self.contentView addSubview:_deleteButton];
        [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.right.offset(-13);
            make.width.height.mas_equalTo(25);
        }];
        @weakify(self);
        [self.deleteButton bk_addEventHandler:^(id sender) {
            @strongify(self);
            if ([self.delegate respondsToSelector:@selector(farmListCellTableViewCellOnDelete:)]) {
                [self.delegate farmListCellTableViewCellOnDelete:self];
            }
        } forControlEvents:UIControlEventTouchUpInside];

        _editButton = [[UIButton alloc] init];
        [self.contentView addSubview:_editButton];
        [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.right.equalTo(self.deleteButton.mas_left).offset(-13);
            make.width.height.mas_equalTo(25);
        }];
        [self.editButton bk_addEventHandler:^(id sender) {
            @strongify(self);
            if ([self.delegate respondsToSelector:@selector(farmListCellTableViewCellOnEdit:)]) {
                [self.delegate farmListCellTableViewCellOnEdit:self];
            }
        } forControlEvents:UIControlEventTouchUpInside];

        
        [self.deleteButton setImage:[UIImage imageNamed:@"home_icon_del"] forState:UIControlStateNormal];
        [self.editButton setImage:[UIImage imageNamed:@"home_icon_edit"] forState:UIControlStateNormal];
        self.deleteButton.hidden = YES;
        self.editButton.hidden = YES;
        
        self.titleLabel.font = SCFont(14);
        self.contentView.backgroundColor = [UIColor contentBackgroundColor];

        
    }
    return self;
}

- (void)setCustomEdit:(BOOL)customEdit {
    self.selectIconView.hidden = customEdit;
    self.editButton.hidden = !customEdit;
    self.deleteButton.hidden = !customEdit;
}

- (void)setCheck:(BOOL)check {
    self.titleLabel.textColor = check ? [UIColor themeColor] : [UIColor textContentColor];
    self.selectIconView.image = [UIImage imageNamed:check ? @"home_edit_check" : @"home_edit_check1"];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end
